import OssUpload from 'wx-oss-upload' // 上传插件
import http from '@/pages/request/index'

 
/**
 * @description 参数以对象形式传入
 * @param {String} host 存储空间访问域名 必填
 * @param {String} bucketType 桶存储类型
 * @param {String} folder 文件存放位置路径，例如 /xx/xx/
 * @param {String} filePath 本地上传文件路径 必填
 * @param {String} fileName 本地上传文件名称
 */
export async function uploadFile(data) {
    // 后台获取签名方法
	const params = await http('oss.config')
 
	const {
		accessKeyId,
		accessKeySecret,
		securityToken,
		expire
	} = params.data;
 
	const ossUpload = new OssUpload({
		accessKeyId,
		accessKeySecret,
		expirationTime: expire 
	})
 
	return await ossUpload.uploadFile({
		host: data.host,
		folder: data.folder,
		filePath: data.filePath,
		fileName: data.fileName,
		securityToken
	})
}